package com.learn.yh.aws;

import org.springframework.core.env.PropertiesPropertySource;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: Yh
 * @date: 2021/4/6 16:25
 */
public class AwsPropertySource extends PropertiesPropertySource {

    public AwsPropertySource(String name, Map<String, Object> source) {
        super(name, source);
    }

    public static AwsPropertySource of(String name, Map<String, AwsSecret> secretMap) {
        Map<String, Object> target = new HashMap<>();
        for (Map.Entry<String, AwsSecret> entry : secretMap.entrySet()) {
            String key = entry.getKey();
            AwsSecret value = entry.getValue();
            if (value == null) {
                continue;
            }
            Map<String, Object> replace = value.replace(key);
            target.putAll(replace);
        }
        return new AwsPropertySource(name, target);
    }
}
